/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Entity.Etbl_Package_tours;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author mrteo
 */
public class DALtbl_Package_tours extends BaseConnection {
    CallableStatement clbStm=null;
    ResultSet rs=null;
    public boolean addtbl_Package_tours(Etbl_Package_tours obj){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Package_tours_add(?,?,?,?,?,?,?,?,?)}");
            clbStm.setInt("packagetour_Id", obj.getPackagetour_Id());
            clbStm.setString("name",obj.getName());
            clbStm.setString("description",obj.getDescription());   
            clbStm.setDate("startDate", obj.getStartDate());
            clbStm.setDate("endDate", obj.getEndDate());
            clbStm.setFloat("price", obj.getPrice());
            clbStm.setString("salesType", obj.getSalesType());
            clbStm.setFloat("salesValues", obj.getSalesValues());
            clbStm.setString("images", obj.getImages());
            clbStm.execute();
            clbStm.close();
            releaseConnection();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Package_tours.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public boolean edittbl_Package_tours(Etbl_Package_tours obj){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Package_tours_update(?,?,?,?,?,?,?,?,?,?)}");
            clbStm.setInt("packagetour_Id", obj.getPackagetour_Id());
            clbStm.setInt("tourtype_Id", obj.getTourtype_Id());
            clbStm.setString("name",obj.getName());
            clbStm.setString("description",obj.getDescription());   
            clbStm.setDate("startDate", obj.getStartDate());
            clbStm.setDate("endDate", obj.getEndDate());
            clbStm.setFloat("price", obj.getPrice());
            clbStm.setString("salesType", obj.getSalesType());
            clbStm.setFloat("salesValues", obj.getSalesValues());
            clbStm.setString("images", obj.getImages());
            clbStm.execute();
            rs.close();
            releaseConnection();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Package_tours.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public boolean deletetbl_Package_tours(int packagetour_Id){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Package_tours_delete(?)}");
            clbStm.setInt("packagetour_Id", packagetour_Id);
            clbStm.execute();
            clbStm.close();
            releaseConnection();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Package_tours.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public Etbl_Package_tours getOnetbl_Package_tours(int packagetour_Id){
      Etbl_Package_tours obj=new Etbl_Package_tours();
      try {
        getConnection();
        clbStm=cnn.prepareCall("{call tbl_Package_tours_get(?)}");
        clbStm.setInt("packagetour_Id",packagetour_Id);              
        rs=clbStm.executeQuery();            
        while(rs.next()){                            
            obj.setPackagetour_Id(rs.getInt("packagetour_Id"));
            obj.setName(rs.getString("name"));
            obj.setDescription(rs.getString("description"));
            obj.setStartDate(rs.getDate("startDate"));
            obj.setStartDate(rs.getDate("endDate"));
            obj.setPrice(rs.getFloat("price")); 
            obj.setSalesType(rs.getString("salesType"));
            obj.setSalesValues(rs.getFloat("salesValues"));
            obj.setImages(rs.getString("images"));
            obj.setTourtype_Id(rs.getInt("tourtype_Id"));
            obj.setTourtype_Name(rs.getString("tourtype_name"));
        }            
        clbStm.close();
        rs.close();
        releaseConnection();
    } catch (SQLException ex) {
        Logger.getLogger(DALtbl_Package_tours.class.getName()).log(Level.SEVERE, null, ex);

    }finally{
          return obj;
      }
  }
        
    public ArrayList getListPackagetours(String orderBy, String ASCorDESC, String WhereClause, int PagingIndex, int PagingSize){
        try {
            ArrayList PackagetoursList=new ArrayList();
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Package_tours_getpaged(?,?,?,?,?)}");
            clbStm.setString("OrderBy", orderBy);
            clbStm.setString("TangGiam", ASCorDESC);
            clbStm.setString("WhereClause", WhereClause);
            clbStm.setInt("PageIndex", PagingIndex);
            clbStm.setInt("PageSize", PagingSize);
            rs=clbStm.executeQuery();
            DALTotalPageIndex.getTotalPage("tbl_Package_tours", WhereClause, PagingSize);
            while(rs.next()){
                Etbl_Package_tours obj=new Etbl_Package_tours();
                obj.setPackagetour_Id(rs.getInt("packagetour_Id"));
                obj.setName(rs.getString("name"));
                obj.setDescription(rs.getString("description"));
                obj.setStartDate(rs.getDate("startDate"));
                obj.setStartDate(rs.getDate("endDate"));
                obj.setPrice(rs.getFloat("price")); 
                obj.setSalesType(rs.getString("salesType"));
                obj.setSalesValues(rs.getFloat("salesValues"));
                obj.setImages(rs.getString("images"));
                obj.setTourtype_Id(rs.getInt("tourtype_Id"));
                obj.setTourtype_Name(rs.getString("tourtype_name"));
                PackagetoursList.add(obj);
            }
            clbStm.close();
            rs.close();
            releaseConnection();
            return PackagetoursList;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Package_tours.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }    
}
